package com.onlinemovies.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import com.onlinemovies.entity.HallDetails;
import com.onlinemovies.service.HallService;



@Controller
@RequestMapping(value = { "/hall" })

public class HallController {

	@Autowired
	private HallService hallService;	
	
	@RequestMapping(value = { "", "/" })
	public ModelAndView halldetails() throws Exception {

		Map<String, Object> params = new HashMap<String, Object>();

		List<HallDetails> halls = hallService.getAll();

		params.put("halls", halls);

		params.put("hall", new HallDetails());

		return new ModelAndView("hall", params);
	}
	
	@RequestMapping("/insert")
	public ModelAndView insert(@ModelAttribute("hall") HallDetails hall)
			throws Exception {

		Map<String, Object> params = new HashMap<String, Object>();

		if (!StringUtils.hasText(hall.getHallname())) {

			params.put("hallnameMessage", "Input required");

			//return new ModelAndView("hall", params);
			return new ModelAndView("redirect:/hall");


		}

		hallService.doInsert(hall);

		//return new ModelAndView("hall",null);
		return new ModelAndView("redirect:/hall");
	}


	@RequestMapping("/about")
	public ModelAndView about() throws Exception {
		return new ModelAndView("about", null);
	}
	
}
